﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace SageKing.Core.Options
{
    public class IdGeneratorOptions
    {
        public virtual short Method { get; set; } = 1;


        public virtual DateTime BaseTime { get; set; } = new DateTime(2020, 2, 20, 2, 20, 2, 20, DateTimeKind.Utc);


        public virtual ushort WorkerId { get; set; }

        public virtual byte WorkerIdBitLength { get; set; } = 6;


        public virtual byte SeqBitLength { get; set; } = 6;


        public virtual int MaxSeqNumber { get; set; }

        public virtual ushort MinSeqNumber { get; set; } = 5;


        public virtual int TopOverCostCount { get; set; } = 2000;


        public virtual uint DataCenterId { get; set; }

        public virtual byte DataCenterIdBitLength { get; set; }

        public virtual byte TimestampType { get; set; }

        public IdGeneratorOptions()
        {
        }

        public IdGeneratorOptions(ushort workerId)
        {
            WorkerId = workerId;
        }
    }

    /// <summary>
    /// 雪花Id配置选项
    /// </summary>
    public sealed class SnowIdOptions : IdGeneratorOptions
    {
        /// <summary>
        /// 缓存前缀
        /// </summary>
        public string WorkerPrefix { get; set; }
    }

    public sealed class TemplateConfigSetOtions
    {
        public Dictionary<string, JsonColumnProperties> JsonColumn { get; set; }
    }
    public class JsonColumnPropertiesBase
    {
        public object Value { get; set; }
    }

    public sealed class JsonColumnProperties : JsonColumnPropertiesBase
    {
        public string Name { get; set; }
        public string Type { get; set; }
        public string DefaultValue { get; set; }

        public JsonColumnOptions Options { get; set; }

        [JsonIgnore]
        [System.Text.Json.Serialization.JsonIgnore]
        public bool IsSelect
        {
            get => Options?.IsSelect ?? false;
        }
        [JsonIgnore]
        [System.Text.Json.Serialization.JsonIgnore]
        public bool Multiple
        {
            get => Options?.Multiple ?? false;
        }

        [JsonIgnore]
        [System.Text.Json.Serialization.JsonIgnore]
        public string Format
        {
            get
            {
                string format = string.Empty;
                Options?.Data?.TryGetValue("Format", out format);
                return format ?? "";
            }
        }
    }

    public sealed class JsonColumnOptions
    {
        /// <summary>
        /// 是否是下拉选择框
        /// </summary>
        public bool IsSelect { get; set; } = false;
        /// <summary>
        /// 是否多选
        /// </summary>
        public bool Multiple { get; set; } = false;

        /// <summary>
        ///  数据类型: dictionary, sql,list, api
        /// </summary>
        public string Type { get; set; } = "dictionary";

        /// <summary>
        /// 数据源
        /// </summary>
        public Dictionary<string, string> Data { get; set; }
    }
}
